var modelDetailFun = {};
modelDetailFun.index = 0;
modelDetailFun.init = function () {

}

modelDetailFun.initTable = function () {
    $("#griddetailtable").html("")
    var h = modelDetailFun.buidHead();
    h += modelDetailFun.buidRow("id", "主键", "String", true);
    $("#griddetailtable").html(h)
}
modelDetailFun.addRow = function () {
    $("#griddetailtable").append(modelDetailFun.buidRow())
}
modelDetailFun.deleteRow = function (nowRow) {
    $("#attTr_" + nowRow).remove();
}
modelDetailFun.buidHead = function () {
    var h = "<tr>";
    h += "<td>属性</td>";
    h += "<td>名称</td>";
    h += "<td>类型</td>";
    h += "<td><a href=\"#\" onclick=\"modelDetailFun.addRow()\" class=\"layui-btn layui-btn-xs\">新增</a></td>";
    h += "</tr>"
    return h;
}
modelDetailFun.buidRow = function (attCode, attName, attType, canNotDel) {
    var nowIndex = modelDetailFun.index++;
    var h = "<tr id='attTr_" + nowIndex + "'>";
    h += '<td style="padding:5px;">';
    h += '<input type="hidden" name="itemRowIndex" value="' + nowIndex + '">';
    if (attCode) {
        h += '<input type="text" name="itemKey_' + nowIndex + '" value="' + attCode + '"  style="display: block;width: 100%;height: 28px;">';
    } else {
        h += '<input type="text" name="itemKey_' + nowIndex + '"  style="display: block;width: 100%;height: 28px;">';
    }
    h += '</td>';

    h += '<td style="padding:5px;">';
    if (attName) {
        h += '<input type="text" name="itemName_' + nowIndex + '" value="' + attName + '"  style="display: block;width: 100%;height: 28px;">';
    } else {
        h += '<input type="text" name="itemName_' + nowIndex + '"  style="display: block;width: 100%;height: 28px;">';
    }
    h += '</td>';

    h += '<td style="padding:5px;">';
    h += '<select name="itemName_' + nowIndex + '" style="display: block;width: 100%;height: 31px;">';
    if (attType == 'String') {
        h += '<option value="String">String</option>';
    } else {
        h += '<option value="String" checked>String</option>';
    }
    if (attType == 'Long') {
        h += '<option value="Long">Long</option>';
    } else {
        h += '<option value="Long" checked>Long</option>';
    }
    if (attType == 'DateTime') {
        h += '<option value="DateTime">DateTime</option>';
    } else {
        h += '<option value="DateTime" checked>DateTime</option>';
    }
    h += '<select>';
    h += '</td>';

    if (canNotDel) {
        h += '<td></td>';
    } else {
        h += '<td><a href="#" onclick="modelDetailFun.deleteRow(\'' + nowIndex + '\')" class="layui-btn layui-btn-danger layui-btn-xs">删除</a></td>';
    }
    h += "</tr>"
    return h;
}
modelDetailFun.deleteLine = function () {

}
$(function () {
    modelDetailFun.initTable();
});